<template>

  <div id="loginContainer">
    <div class="login-title">
      <span class="title">登录</span>
    </div>
    <div class="login-box">
      <el-form :model="loginForm" status-icon :rules="loginRules" ref="loginForm" label-width="0px">
        <el-form-item prop="email">
          <el-input type="text" v-model="loginForm.email" autocomplete="on" placeholder="邮箱"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="loginForm.password" autocomplete="on" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-button style="width:100%;" class="autoWidthButton" @click="submitLogin" type="primary">登录</el-button>
            </el-col>
            <el-col :span="12">
              <el-button class="autoWidthButton" @click="toRegister">注册</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { adminLogin } from '@/api/admin/user'
import { mapMutations } from 'vuex'
export default {
  data() {
    return {
      check: true,
      loginForm: {
        email: "",
        password: "",
      },
      loginRules: {
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      }
    }
  },
  methods: {
    ...mapMutations({
      setUserMsg: 'user/setUserMsg'
    }),
    //去注册
    toRegister() {
      this.$router.push({
        path: '/admin/register'
      })
    },
    //去找回密码
    toFindPassword() {
      this.$router.push({
        path: '/admin/findpassword'
      })
    },
    //登录
    submitLogin() {
      this.$refs['loginForm'].validate((valid) => {
        if (valid) {
          adminLogin(this.loginForm, (res) => {
            if (res.code == 200) {
              this.setUserMsg(res.data)
              this.$router.push({
                path:'/admPage/index'
              })
            }
          }, true)
          return false
        } else {
          return false;
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>